{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>adm_stuInfo</title>
    <link rel="stylesheet" href="{% static 'css/sqlTable.css' %}">
    <link rel="stylesheet" href="{% static 'css/navbar.css' %}">
    <link rel="stylesheet" href="{% static 'css/pagination.css' %}">
    <link rel="stylesheet" href="{% static 'css/search.css' %}">
    <script type="text/javascript" src="{% static 'js/click.js' %}"></script>
</head>
<body>
<body background="{% static 'img/adm.jpg' %}" style="background-repeat:no-repeat ;background-size:100% 100%;background-attachment: fixed;">
    {% load static %}
    <!-- 导航栏 -->
    <div class="navbar">
        <div class="system-name">图书馆图书借阅系统——学生信息</div>
        <nav class="menu">
            <a href="/adm_index" class="menu-item">系统首页</a>
            <a href="/adm_book" class="menu-item">查看图书</a>
            <a href="/adm_borrow" class="menu-item">借阅记录</a>
            <a href="/adm_stuInfo" class="menu-item">学生信息</a>
            <a href="/adm_info" class="menu-item">个人中心</a>
        </nav>
        <div class="user-info">
            <span class="username">欢迎您，管理员：{{ adm_id }}</span>
            <a href="/login">
                <button class="button">退出</button>
            </a>
        </div>
    </div>
    <div class="search-bar">
        <form action="" method="post" name="search">
            {% csrf_token %}
            <input type="hidden" name="form_id" value="search">
            <input type="text" name="quest" placeholder="搜索学生..." required>
            <select id="category" name="category">
                <option value="stu_name">学生姓名</option>
                <option value="stu_id">学生学号</option>
                <option value="stu_college">所属学院</option>
                <option value="stu_major">所学专业</option>
                <option value="stu_phone">手机号</option>
            </select>
            <input type="submit" value="搜索">
        </form>
        <p>
            {% if quest and category %}
            {% if category == 'stu_name' %}
                搜索方式：学生姓名
                搜索内容：{{ quest }}
            {% elif category == 'stu_id' %}
                搜索方式：学生学号
                搜索内容：{{ quest }}
            {% elif category == 'stu_college' %}
                搜索方式：所属学院
                搜索内容：{{ quest }}
            {% elif category == 'stu_major' %}
                搜索方式：所学专业
                搜索内容：{{ quest }}
            {% elif category == 'stu_phone' %}
                搜索方式：手机号
                搜索内容：{{ quest }}
            {% endif %}
        {% endif %}
        </p>

    <p style="color: red">
        {% if err %}
            {{ err }}
        {% endif %}
        </p>
    </div>

    <div class= "container">
        <table>
            <thead>
                <tr>
                    <th>学生头像</th>
                    <th>学号</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>所属学院</th>
                    <th>所学专业</th>
                    <th>手机号</th>
                    <th>未还书籍数量</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for student in stu_queryset %}
                <tr>
                    <td><img src="{{ student.avatar }}" alt="学生头像" style="width: 50px; height: 50px; object-fit: cover;"></td>
                    <td>{{ student.stu_id }}</td>
                    <td>{{ student.stu_name }}</td>
                    <td>{{ student.stu_gender }}</td>
                    <td>{{ student.stu_age }}</td>
                    <td>{{ student.stu_college }}</td>
                    <td>{{ student.stu_major }}</td>
                    <td>{{ student.stu_phone }}</td>
                    <td>{{ student.stu_borrowNum }}</td>
                    <form method="post" action="">
                        {% csrf_token %}
                        <input type="hidden" name="form_id" value="delete">
                        <input type="hidden" name="stu_id" value="{{ student.stu_id }}">
                        <td class="action-column">
                            <input type="submit" value="删除" class="tablebutton">
                        </td>
                    </form>
                </tr>
                {% endfor %}
            </tbody>
        </table>
        <div class="pagination">
            <form method="get" action=".">
                {% csrf_token %}
                {% if stu_queryset.has_previous %}
                    <button type="submit" name="page" value="1">&laquo; 第一页</button>
                    <button type="submit" name="page" value="{{ stu_queryset.previous_page_number }}">上一页</button>
                {% endif %}

                <span class="current">
                    页码 {{ stu_queryset.number }} / {{ stu_queryset.paginator.num_pages }}
                </span>

                {% if stu_queryset.has_next %}
                    <button type="submit" name="page" value="{{ stu_queryset.next_page_number }}">下一页</button>
                    <button type="submit" name="page" value="{{ stu_queryset.paginator.num_pages }}">最后一页 &raquo;</button>
                {% endif %}
                {% if quest %}
                    <input type="hidden" name="quest" value="{{ quest }}">
                    <input type="hidden" name="category" value="{{ category }}">
                    <input type="hidden" name="form_id" value="search">
                {% endif %}
                </form>
        </div>

    </div>
    <form method="get" action="/export_to_excel/">
        <input type="hidden" name="quest" value="{{ quest }}">
        <input type="hidden" name="category" value="{{ category }}">
        <input type="hidden" name="exportId" value="student">
        <input type="submit" value="导出学生信息数据"  class="belowButton">
    </form>

</body>
</html>